package com.yrw.zcy.sort;

/**
 * @ClassName BubbleSort
 * @Author 12694
 * @Date 2024/11/3 19:47
 * @Version 1.0
 **/
public class BubbleSort {
    public static void main(String[] args) {
        int[] arr = {5, 4, 3, 2, 1};
        for (int end=arr.length-1;end>0;end--){
            for (int i=0;i<end;i++){
                if (arr[i]>arr[i+1]){
                    swap(arr[i],arr[i+1]);
                }
            }
        }
        for (int i : arr) {
            System.out.println(i);
        }
    }

    public static void swap(int a, int b)  {
        int temp = a;
        a = b;
        b = temp;
    }
}
